<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>  
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
  <title>职位管理</title>
  
  <script>
    var selectPositionTypeModalInited = false;
    $(document).ready(function() {
      //聚焦第一个输入框
      $("#position_name").focus();
      //为inputForm注册validate函数
      $("#inputForm").validate();

      var names = [ '${position.posType.name}', '${position.posType2.name}' ];
      for (var i = names.length - 1; i >= 0; i--) {
        if (!names[i]) {
            names.splice(i);
        }
      }
      $('#position_type_names').text(names.join('，'));

      $('#select_position_type').click(function() {
        if (!selectPositionTypeModalInited) {
          $.get('${ctx}/helper/select-position-type-modal', function(html) {
            $('#select_position_type_modal').html(html);
            callSelectPositionTypeModal();
            selectPositionTypeModalInited = true;
          });
        } else {
          callSelectPositionTypeModal();
        }
      });

      initProvinceCitySelect();
    });

    function callSelectPositionTypeModal() {
      SelectPositionTypeModal.init();
      $('#select_position_type_modal').data('maxSelected', 2).data('selectedIds', [ $('#position_type_id').val(), $('#position_type2_id').val() ]).data('callback', updateSelectedPositionTypes).modal('show');
    }

    function updateSelectedPositionTypes(selectedPositionTypes) {
      if (selectedPositionTypes) {
        var names = [];
        if (selectedPositionTypes.length > 0) {
          $('#position_type_id').val(selectedPositionTypes[0].id);
          names.push(selectedPositionTypes[0].name);
        } else {
          $('#position_type_id').val('');
        }
        if (selectedPositionTypes.length > 1) {
          $('#position_type2_id').val(selectedPositionTypes[1].id);
          names.push(selectedPositionTypes[1].name);
        } else {
          $('#position_type2_id').val('');
        }
        $('#position_type_names').text(names.join('，'));
      }
    }

    function initProvinceCitySelect() {
      $('#position_province').change(function() {
        var container = $('#position_city_container');
        var cities = $('#position_city');
        cities.children('option[value!="0"]').appendTo(container);
        var number = container.children('[value^=' + $(this).val() + ']').appendTo(cities).length;
        cities.children(number === 1 ? ':last' : ':first').attr('selected', '');
      }).change();
    }
  </script>
</head>

<body>
  <form:form id="inputForm" action="${ctx}/hr/position/${action}" method="post" class="form-horizontal" commandName="position">
    <input type="hidden" name="id" value="${position.id}"/>
    <input type="hidden" name="companyId" value="${companyId}"/>
    <fieldset>
      <legend><small>管理职位</small></legend>
      <div class="control-group">
        <label for="position_name" class="control-label">职位名称:</label>
        <div class="controls">
          <input type="text" id="position_name" name="name"  value="${position.name}" class="input-large required" minlength="3"/>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_department" class="control-label">部门:</label>
        <div class="controls">
          <form:select id="position_department" path="departmentId">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${departments.content}" itemLabel="name" itemValue="id" />
          </form:select>
        </div>
      </div>
      <div class="control-group">
        <label for="position_code" class="control-label">职位编号:</label>
        <div class="controls">
          <input type="text" id="position_code" name="code"  value="${position.code}" class="input-large"/>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_count" class="control-label">招聘人数:</label>
        <div class="controls">
          <input type="text" id="position_count" name="count"  value="${position.count}" class="input-large required"/>
        </div>
      </div>
      <div class="control-group">
        <label for="position_province" class="control-label">所属地区:</label>
        <div class="controls">
          <form:select id="position_province" path="province" class="span3">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${provinces}" itemLabel="name" itemValue="id" />
          </form:select>
          <select id="position_city" name="city" class="span3">
            <option value="0">--- 请选择 ---</option>
          </select>
          <form:select id="position_city_container" path="city" items="${cities}" itemLabel="name" itemValue="id" class="hide"/>
        </div>
      </div>
      <div class="control-group">
        <label for="position_age" class="control-label">年龄:</label>
        <div class="controls">
          <input type="text" id="position_minAge" name="minAge"  value="${position.minAge}" class="input-large"/>到
          <input type="text" id="position_minAge" name="maxAge"  value="${position.maxAge}" class="input-large"/>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_positionType" class="control-label">职能类别:</label>
        <div class="controls">
          <span class="span5 uneditable-input" id="position_type_names"></span>
          <input type="hidden" id="position_type_id" name="positionTypeId" value="${position.posType.id}" />
          <input type="hidden" id="position_type2_id" name="positionType2Id" value="${position.posType2.id}" />
          <a id="select_position_type" class="btn">选择</a>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_language" class="control-label">语言 1:</label>
        <div class="controls">
          <form:select id="position_language" path="language">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${languages}" itemLabel="name" itemValue="id" />
          </form:select>
          <form:select id="position_proficiency" path="proficiency" items="${proficiencys}" itemLabel="name" itemValue="id"/>
        </div>
      </div>
      <div class="control-group">
        <label for="position_language2" class="control-label">语言 2:</label>
        <div class="controls">
          <form:select id="position_language2" path="language2">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${languages}" itemLabel="name" itemValue="id" />
          </form:select>
          <form:select id="position_proficiency2" path="proficiency2" items="${proficiencys}" itemLabel="name" itemValue="id"/>
        </div>
      </div>
      <div class="control-group">
        <label for="position_education" class="control-label">学历:</label>
        <div class="controls">
          <form:select id="position_education" path="education">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${educations}" itemLabel="name" itemValue="id" />
          </form:select>
        </div>
      </div>
      <div class="control-group">
        <label for="position_workingYears" class="control-label">工作年限:</label>
        <div class="controls">
          <form:select id="position_workingYears" path="workingYears" items="${workingYears}" itemLabel="name" itemValue="id"/>
        </div>
      </div>
      <div class="control-group">
        <label for="position_major" class="control-label">专业 1:</label>
        <div class="controls">
          <form:select id="position_major" path="major">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${majors}" itemLabel="name" itemValue="id" />
          </form:select>
        </div>
      </div>
      <div class="control-group">
        <label for="position_major2" class="control-label">专业 2:</label>
        <div class="controls">
          <form:select id="position_major2" path="major2">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${majors}" itemLabel="name" itemValue="id" />
          </form:select>
        </div>
      </div>
      <div class="control-group">
        <label for="position_salaryRange" class="control-label">月薪:</label>
        <div class="controls">
          <form:select id="position_salaryRange" path="salaryRange">
            <option value="0">--- 请选择 ---</option>
            <form:options items="${salaryRanges}" itemLabel="name" itemValue="id" />
          </form:select>
        </div>
      </div>
      <div class="control-group">
        <label for="position_jobType" class="control-label">工作性质:</label>
        <div class="controls">
          <c:set var="checked" value=""/>
          <c:if test="${position.jobType == 0}"><c:set var="checked" value="checked"/></c:if>
          <input type="radio" name="jobType" value="0" ${checked}>全职
          <c:set var="checked" value=""/>
          <c:if test="${position.jobType == 1}"><c:set var="checked" value="checked"/></c:if>
          <input type="radio" name="jobType" value="1" ${checked}>兼职
        </div>
      </div>
      <div class="control-group">
        <label for="position_keyword" class="control-label">关键字:</label>
        <div class="controls">
          <input type="text" id="position_keyword" name="keyword"  value="${position.keyword}" class="input-large"/>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_description" class="control-label">职位描述/岗位要求:</label>
        <div class="controls">
          <textarea id="position_description" name="description" class="input-large">${position.description}</textarea>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_descriptionEng" class="control-label">职位描述/岗位要求(英文):</label>
        <div class="controls">
          <textarea id="position_descriptionEng" name="descriptionEng" class="input-large">${position.descriptionEng}</textarea>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_order" class="control-label">排序:</label>
        <div class="controls">
          <input type="text" id="position_order" name="order"  value="${position.order}" class="input-large"/>
        </div>
      </div>  
      <div class="control-group">
        <label for="position_quota" class="control-label">每日投放限额:</label>
        <div class="controls">
          <input type="text" id="position_quota" name="quota"  value="${position.quota}" class="input-large"/>
        </div>
      </div>  

      <div class="form-actions">
        <input id="submit_btn" class="btn btn-primary" type="submit" value="提交"/>&nbsp;  
        <input id="cancel_btn" class="btn" type="button" value="返回" onclick="history.back()"/>
      </div>
    </fieldset>
  </form:form>
  <div id="select_position_type_modal" class="modal hide fade"></div>
</body>
</html>
